/* 
 * Advanced Foundation Classes
 * Copyright (C) 2000/2004  Fabio Rotondo - Andrea Galimberti
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef AFC_EASYGUI_WIDGETS_H
#define AFC_EASYGUI_WIDGETS_H

#include <gtk/gtk.h>

#include "easygui.h"

// Widget Attributes
#define AFC_EASYGUI_WIDGET_ATTR_VALUE		AFC_EASYGUI_BASE + 1
#define AFC_EASYGUI_WIDGET_ATTR_VISIBLE		AFC_EASYGUI_BASE + 2
#define AFC_EASYGUI_WIDGET_ATTR_ACTIVE		AFC_EASYGUI_BASE + 3
#define AFC_EASYGUI_WIDGET_ATTR_FOCUS		AFC_EASYGUI_BASE + 4
#define AFC_EASYGUI_WIDGET_ATTR_NAME		AFC_EASYGUI_BASE + 5

#include "widgets/button.h"
#include "widgets/checkbutton.h"
#include "widgets/clist.h"
#include "widgets/cols.h"
#include "widgets/combo.h"
#include "widgets/drawingarea.h"
#include "widgets/entry.h"
#include "widgets/eqcols.h"
#include "widgets/eqrows.h"
#include "widgets/eventbox.h"
#include "widgets/frame.h"
#include "widgets/label.h"
#include "widgets/menubar.h"
#include "widgets/menu.h"
#include "widgets/optmenu.h"
#include "widgets/radiobutton.h"
#include "widgets/rows.h"
#include "widgets/scrolledwindow.h"
#include "widgets/separator.h"
#include "widgets/tabs.h"
#include "widgets/tclist.h"
#include "widgets/toolbar.h"
#include "widgets/window.h"

// Widget Functions
int afc_easygui_widget_connect_signal ( DynamicClass * dyn, GtkWidget * w, char * event, char * func_name, guint * sig_id, GtkSignalFunc default_func );
void * afc_easygui_widget_get_callback ( DynamicClass * dyn, char * event_name );
int afc_easygui_widget_parse_default_params ( EasyGUI * easygui );
int afc_easygui_widget_standard_free ( DynamicClass * dyn );
GList * afc_easygui_widget_make_glist ( EasyGUI * easygui, char * items );
GtkWidget * afc_easygui_widget_create_label ( DynamicClass * dc, char * text, char * iconname, int horientation );

/* ===================================================================================
   CONTEXT FUNCTIONS
=================================================================================== */
#define afc_easygui_get_context(egui,name)		afc_dictionary_get ( egui->contexts, name )
#define afc_easygui_context_get_widget(context,wname)	afc_dictionary_get ( context->widgets, wname )

int afc_easygui_widget_set_attrs     		( EasyGUIContext * context, char * wname, ... );
int afc_easygui_widget_get_attr       		( EasyGUIContext * context, char * wname, int attr, void * buffer );
int afc_easygui_widget_set_attr       		( EasyGUIContext * context, char * wname, int attr, void * buffer );
int afc_easygui_widget_execute        		( EasyGUIContext * context, char * wname, char * method, ... );
int afc_easygui_context_show_menu     		( EasyGUIContext * context, DynamicClass * dc, char * menu_name );
int afc_easygui_widget_store_function 		( EasyGUIContext * context, DynamicClass * dyn, const char * event, const char *  func_name );
int afc_easygui_widget_get_horient 		( EasyGUIContext * context, char * horient );
int afc_easygui_widget_get_relief 		( EasyGUIContext * context, char * relief );
int afc_easygui_widget_add_default_events 	( EasyGUIContext * context, DynamicClass * dc, GtkWidget * w );

/* widgets initialization */
int afc_easygui_internal_init_widgets ( EasyGUI * );

#define WIDGET_SET_CONTEXT(dc,context)	\
		afc_dynamic_class_set_var ( dc, AFC_DYNAMIC_CLASS_VAR_KIND_POINTER, "egui_context", context )

#define WIDGET_GET_CONTEXT(dc)\
	afc_dynamic_class_get_var ( dc, "egui_context" )

#define WIDGET_SET_ICON(dc,icon)	\
		afc_dynamic_class_set_var ( dc, AFC_DYNAMIC_CLASS_VAR_KIND_POINTER, "egui_icon", icon )

#define WIDGET_GET_ICON(dc)	\
		afc_dynamic_class_get_var ( dc, "egui_icon" )

#define WIDGET_GET_CALLBACK(dc,name)	(EasyGUISignalFunc) afc_dictionary_get ( dc->private_vars, name )

#define WIDGET_GET_CALLBACK_CAST(dc,name,sig,cast) \
	if ( ( sig = ( cast ) afc_dictionary_get ( dc->private_vars, name ) ) == NULL ) return;

#define WIDGET_CALL_FUNC(dc,sig)		if ( sig != NULL ) sig ( dc, WIDGET_GET_CONTEXT ( dc ) );

#define WIDGET_CALL_CALLBACK(dc,sig,name)	\
	if ( dc->private_vars ) \
	  if ( ( sig = ( EasyGUISignalFunc ) afc_dictionary_get ( dc->private_vars, name ) ) != NULL )  sig ( dc, WIDGET_GET_CONTEXT ( dc ) )

#define WIDGET_GET_EWIDGET(dc,ewd)	\
	if ( ( ewd = afc_dynamic_class_get_var ( dc, "ewidget" ) )	== NULL ) \
		return ( AFC_LOG ( AFC_LOG_ERROR, AFC_EASYGUI_ERR_WIDGET_DATA_NOT_FOUND, "Widget Data is missing", NULL ) );	

#define WIDGET_GET_EWIDGET_VOID(dc,ewd)	\
	if ( ( ewd = afc_dynamic_class_get_var ( dc, "ewidget" ) )	== NULL ) return;


#define WIDGET_FREE_EWIDGET(dc,ewd)	\
	if ( ( ewd = afc_dynamic_class_get_var ( dc, "ewidget" ) ) != NULL ) { \
		afc_free ( ewd ); \
		afc_dynamic_class_set_var ( dc, AFC_DYNAMIC_CLASS_VAR_KIND_POINTER, "ewidget", NULL ); \
	}


#endif
